package com.open.pokergames.texas.view

import android.os.Bundle
import android.os.CountDownTimer
import androidx.appcompat.app.AppCompatActivity
import com.open.pokergames.biz.viewModel.BizViewModel
import com.open.pokergames.comm.repository.entity.UserEntity
import com.open.pokergames.conn.bean.Player
import com.open.pokergames.texas.repository.entity.RoomIM

open abstract class RoomDetailCommActivity : AppCompatActivity() {
    var viewModel: BizViewModel? = null
    var roomIM: RoomIM? = null
    var roomNum: String? = null
    var roomName: String? = null
    var userLogin: UserEntity? = null

//    var groupMember: GroupMemberEntity? = null

    var doFlowAdd = false

    protected fun getCurrPlayer(): Player? {
        for (player in roomIM!!.players.values) {
            if (player.account == userLogin!!.account) {
                return player
            }
        }
        return null
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        viewModel = BizViewModel()
    }

   protected var timerPlayOpt: CountDownTimer = object : CountDownTimer(15000, 1000) {

        override fun onTick(millisUntilFinished: Long) {
//            timerTv.text = "${millisUntilFinished / 1000}s"
            onTickPlayOpt(millisUntilFinished)
        }

        override fun onFinish() {
            onFinishPlayOpt()
        }
    }

    override fun onDestroy() {
        super.onDestroy()
        timerPlayOpt.cancel()
    }

    abstract fun onTickPlayOpt(millisUntilFinished: Long)

    abstract fun onFinishPlayOpt()

}